package com.ls.kdlss.util;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.wx.android.common.util.JsonUtils;

/**
 * Created by Administrator on 2016/11/11.
 */

public class BGWebView extends AppCompatActivity {

    public static String url = "";
    public static WebView wv_webcontent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    public void setWebView() {
        url = "";
        Log.e("URL", url);
        wv_webcontent.loadUrl(url);
        WebSettings settings = wv_webcontent.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setUseWideViewPort(true); //将图片调整到适合WebView的大小
        settings.setLoadWithOverviewMode(true); //自适应屏幕
        wv_webcontent.addJavascriptInterface(BGWebView.this, "javaweb");

    }

    //聊天
    @JavascriptInterface
    public void jsCall(String str) {

        WebViewEntity viewEntity = JsonUtils.jsonToObject(str, WebViewEntity.class);


        if (viewEntity.getType().equals("1")) {
            WebViewOne();

        } else if (viewEntity.getType().equals("2")) {

            WebViewTow();
        }
    }


    public void WebViewOne() {


    }

    public void WebViewTow() {


    }

    class WebViewEntity {


        /**
         * type : 123
         * url : www.baidu.com
         * ext1 : 113131
         * ext2 : 123131
         */

        private String type;
        private String url;
        private String ext1;
        private String ext2;

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

        public String getExt1() {
            return ext1;
        }

        public void setExt1(String ext1) {
            this.ext1 = ext1;
        }

        public String getExt2() {
            return ext2;
        }

        public void setExt2(String ext2) {
            this.ext2 = ext2;
        }
    }

}
